package ubadb.core.components.bufferManager.bufferPool.pools.multiple;

import ubadb.core.common.TableId;
import ubadb.core.components.bufferManager.bufferPool.BufferPool;
import ubadb.core.components.bufferManager.bufferPool.pools.single.SingleBufferPool;


/**
 * MultipleBufferPool that defines a pool per table.
 */
public class PerTableMultipleBufferPool extends MultipleBufferPool {
	private final int totalBufferSize;
	
	public PerTableMultipleBufferPool(int totalBufferSize, TablePoolDefinition[] definitions) {
		this.totalBufferSize = totalBufferSize;
		
		for(TablePoolDefinition definition : definitions) {
			TableId tableId = new TableId(definition.getTableName());
			
			int poolSize = (int) (this.totalBufferSize * (definition.getBufferPercentage() / 100.0));
			
			BufferPool bufferPool = new SingleBufferPool(poolSize, definition.getReplacementStrategy());
			
			assignPool(new TableToBufferPoolAssignment(tableId, bufferPool));
		}
	}
}
